import { get, post } from '@/utils/http'
import type { BasicPagingListParams, BasicPagingListResult } from '@/apis/basicModel'

import type {
  ISupplierParams,
  ISupplierResult,
  ICreateSupplierParams,
  ISupplierDetail,
  ICreateUser,
  IEditUser,
  IUser
} from './model/supplierModel'
enum Api {
  // 分页查询供应商
  GET_SUPPLIER_LIST = '/footprint/supplier/pageSupplier',
  // 删除供应商
  DEL_SUPPLIER = '/upms/supplier/deleteSupplier',
  // 新建供应商
  CREATE_SUPPLIER = '/upms/supplier/createSupplier',
  EDIT_SUPPLIER = '/upms/supplier/editSupplier',
  GET_SUPPLIER_DETAIL = '/upms/supplier/getSupplierInfo',

  //供应商用户分页查询
  GET_SUPPLIER_USER_LIST = '/upms/supplierUser/pageSupplierUser',
  DEL_SUPPLIER_USER = '/upms/supplierUser/deleteSupplierUser',
  CREATE_SUPPLIER_USER = '/upms/supplierUser/createSupplierUser',
  EDIT_SUPPLIER_USER = '/upms/supplierUser/modifySupplierUser'
}
// 分页查询供应商
export const getSupplierList = (
  params: ISupplierParams & BasicPagingListParams
): Promise<BasicPagingListResult<ISupplierResult>> => get(Api.GET_SUPPLIER_LIST, params)

export const getSupplierDetail = (supplierNo: string): Promise<ISupplierDetail> =>
  get(Api.GET_SUPPLIER_DETAIL, { supplierNo })

export const delSupplier = (supplierNo: string): Promise<void> =>
  post(Api.DEL_SUPPLIER, { supplierNo })

export const createSupplier = (params: ICreateSupplierParams): Promise<void> =>
  post(Api.CREATE_SUPPLIER, params)

export const editSupplier = (params: ICreateSupplierParams): Promise<void> =>
  post(Api.EDIT_SUPPLIER, params)

export const getSupplierUserList = (
  params: BasicPagingListParams & { enterpriseNo: string }
): Promise<BasicPagingListResult<IUser>> => get(Api.GET_SUPPLIER_USER_LIST, params)
export const delSupplierUser = (userId: string): Promise<void> =>
  post(Api.DEL_SUPPLIER_USER, { userId })
export const createSupplierUser = (params: ICreateUser): Promise<void> =>
  post(Api.CREATE_SUPPLIER_USER, params)
export const editSupplierUser = (params: IEditUser): Promise<void> =>
  post(Api.EDIT_SUPPLIER_USER, params)
